package com.puzzlebazar.client.heyawake;

import java.io.Serializable;

import com.puzzlebazar.client.util.Recti;

public class Room implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5947632970501181987L;
	
	private Recti roomArea;
	private int value;

	/**
	 * Provided only for GWT serialization
	 */
	@SuppressWarnings("unused")
	private Room() {
		this.roomArea = new Recti();
		this.value = -1;
	}

	/**
	 * Creates a room covering a specific area but without value
	 * 
	 * @param roomArea A rectangle describing the area covered by the room
	 */
	public Room( Recti roomArea ) {
		this.roomArea = new Recti(roomArea);
		this.value = -1;
	}
	
	/**
	 * Creates a room with a specific value and covering a specific area
	 * 
	 * @param roomArea A rectangle describing the area covered by the room
	 * @param value The room value (-1 means no value)
	 */
	public Room( Recti roomArea, int value ) {
		assert ( value >= -1 );
		this.roomArea = new Recti(roomArea);
		this.value = value;
	}
	
	/**
	 * Copy constructor
	 * 
	 * @param room The room to copy
	 */
	public Room( Room room ) {
		roomArea = new Recti(room.roomArea);
		value = room.value;
	}
	
	
	/**
	 * @return The rectangle describing the area of the room
	 */
	public Recti getRoomArea() {
		return roomArea;
	}
	
	/**
	 * @return The value of the room (-1 means no value)
	 */
	public int getValue() {
		return value;
	}

	/**
	 * @return A string representing the value
	 */
	public String getStringValue() {
		if( value < 0 ) return "";
		return Integer.toString( value );
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((roomArea == null) ? 0 : roomArea.hashCode());
		result = prime * result + value;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Room other = (Room) obj;
		if (roomArea == null) {
			if (other.roomArea != null)
				return false;
		} else if (!roomArea.equals(other.roomArea))
			return false;
		if (value != other.value)
			return false;
		return true;
	}
}
